#include<ros/ros.h>
#include<geometry_msgs/Twist.h>
#include<stdlib.h>
//带参数的随机控制海龟 参数调整速度（运行节点前需要先设置参数值）
int main(int argc,char** argv){
	ros::init(argc,argv,"publish_velocity_max");
	ros::NodeHandle nh;

	ros::Publisher pub = nh.advertise<geometry_msgs::Twist>("turtle1/cmd_vel",1000);
	srand(time(0));

	const std::string PARAM_NAME="~max_vel";
	double maxVel;
	//获得参数值，赋值maxVel
	bool ok = ros::param::get(PARAM_NAME, maxVel);

	if(!ok){
		ROS_FATAL_STREAM("couldn't get parameter"<<PARAM_NAME);
		exit(1);
	}

	ros::Rate rate(2);
	while(ros::ok()){
		geometry_msgs::Twist msg;
		msg.linear.x = maxVel*double(rand())/double(RAND_MAX);
		msg.angular.z = maxVel*double(rand())/double(RAND_MAX)-1;
		
		pub.publish(msg);
		rate.sleep();
	}
}
